package com.zj.i18n;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.context.support.ResourceBundleMessageSource;
import org.springframework.http.HttpRequest;
import org.springframework.stereotype.Component;

import javax.servlet.http.HttpServletRequest;

public class I18nUtil {
    private static ResourceBundleMessageSource source;
    private static HttpServletRequest request;

    @Autowired
    public void setMessageSource(ResourceBundleMessageSource source) {
        this.source = source;
    }
    @Autowired
    public void setRequest(HttpServletRequest request){
        this.request=request;
    }

    public static String getMessage(String code,String ...args){
        return source.getMessage(code,args,request.getLocale());
    }


}
